<?php
namespace App\Common\Lib\Com\RabbitMQ\_Channel;

use App\Common as com;
use App\Common\Lib\Com\RabbitMQ\_Channel\_Queue as name_Queue;
use App\Common\Lib\Com\RabbitMQ as nameRabbitMQ;
use PhpAmqpLib\Channel\AMQPChannel;

/**
 * @property nameRabbitMQ\DataStore $dataStore
 */
class _Queue extends com\Cla\ClaBase\CommonOfId\Client {

	private AMQPChannel $channel;

	private string $queueName;

	/**
	 * _Exchange constructor.
	 * @param com\Cla\ClaBase\DataStore $dataStore
	 * @param AMQPChannel $channel
	 * @param string $queueName
	 * @throws
	 */
	public function __construct( com\Cla\ClaBase\DataStore $dataStore, AMQPChannel $channel, string $queueName ) {
		parent::__construct( $dataStore );
		//
		$this->channel = $channel;
		//
		$this->queueName = $queueName;
	}

	public function __destruct(  ) {
		// d('__destruct _Queue');
		//
		parent::__destruct();
	}

	/**
	 * @return AMQPChannel
	 */
	public function getChannel(  ):AMQPChannel {
		return $this->channel;
	}

	/**
	 * @return string
	 */
	public function getQueueName(  ):string {
		return $this->queueName;
	}

	/**
	 * 声明队列
	 * @param bool $passive [false][默认]
	 * @param bool $durable [false][默认]
	 * @param bool $exclusive [false][默认]
	 * @param bool $auto_delete [true][默认]
	 * @param bool $nowait [false][默认]
	 * @param array $arguments [[]][默认]
	 * @param null $ticket [null][默认]
	 * @return $this
	 * @throws
	 */
	public function declareQueue (
		bool $passive = false,
		bool $durable = false,
		bool $exclusive = false,
		bool $auto_delete = true,
		bool $nowait = false,
		array $arguments = [],
		$ticket = null
	):self {
		$this->channel->queue_declare( $this->queueName, $passive, $durable, $exclusive, $auto_delete, $nowait, $arguments, $ticket );
		return $this;
	}

	/**
	 * @param string $exchangeName
	 * @param string $routeKey
	 * @return $this
	 * @throws
	 */
	public function bind( string $exchangeName, string $routeKey ):self {
		$this->channel->queue_bind( $this->queueName, $exchangeName, $routeKey );
		return $this;
	}

	/**
	 * @return _Queue\_Consume
	 */
	public function goConsume(  ):name_Queue\_Consume {
		return $this->goPool( __FUNCTION__, function(){
		    return name_Queue\_Consume::make( $this->dataStore, $this->channel, $this->queueName );
		} );
	}

}
